var $ = {
  get : function(url,data,success,dataType){
    var xhr = this.createXhr();
    var str = url +'?'+ data;
    xhr.open('get',str);
    xhr.send();
    xhr.onload = function(){
      var result = xhr.responseText;
      if(dataType == 'json'){
        result = JSON.parse(result);
      };
      success(result);
    };
  },

  post : function(url,data,success,dataType){
    var xhr = this.createXhr();
    xhr.open('post',url);
    xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
    xhr.send(data);
    xhr.onload = function(){
      var result = xhr.responseText;
      if(dataType == 'json'){
        result = JSON.parse(result);
      };
      success(result);
    };
  },

  ajax : function(obj){
    var type = obj.type || 'get';
    var url = obj.url;
    var data = obj.data || '';
    var dataType = obj.dataType || 'text';
    var success = obj.success;

    if(type == 'get'){
      this.get(url,data,success,dataType);
    }else if(type == 'post'){
      this.post(url,data,success,dataType);
    };
  },


  createXhr : function(){
    var xhr = '';
    if(window.XMLHttpRequest){
      xhr = new XMLHttpRequest();
    }else{
      xhr = new ActiveXObject('Msxml2','XMLHTTP');
    };
    return xhr;
  },
}; 